package org2.jogo.activities;

import java.util.List;
import org2.jogo.R;
import org2.jogo.models.Leaderboard;
import org2.jogo.models.Pontuacao;
import adapters.LeaderboardDbAdapter;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class LeaderboardTabActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.leaderboard_tab);
        int dificuldade = Integer.parseInt(getIntent().getStringExtra("dificuldade"));
        ListView lista = (ListView) findViewById(R.id.listaLeaderboard);
        Leaderboard leaderboard = Leaderboard.getInstance();
        LeaderboardDbAdapter adapter = LeaderboardDbAdapter.getDbAdapter(this);
        List<Pontuacao> pontuacoes = leaderboard.getTopFive(adapter, dificuldade);
        if (pontuacoes.size() == 0) {
            lista.setVisibility(View.GONE);
        }
        lista.setAdapter(new SimpleAdapter(this, leaderboard.getHashMapTopFive(pontuacoes),
                    R.layout.leaderboard_item,
                    leaderboard.getColumnNames(), leaderboard.getColumnIds()));
    }
}